package com.ruoyi.manage.strategy.Impl;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.manage.DTO.ChargingDTO;
import com.ruoyi.manage.strategy.BillingPolicies;
import org.omg.CORBA.SystemException;

import java.math.BigDecimal;

/**
 * @Title:
 * @BelongProjecet online-car-hailing
 * @BelongPackage com.ruoyi.manage.strategy.Impl
 * @Description:
 * @Copyright
 * @Author: 马朝斌
 * @Date: 2024-07-03 16:24
 * @Version V1.0
 */
public class OverMileageBillingPolicy implements BillingPolicies {
    
    /**
    * @Author 马朝斌
    * @Description //TODO 订单的超距离计费策略
    * @Date 16:24 2024/7/3
    * @Param 
     * @param chargingDTO
    * @return com.ruoyi.common.core.web.domain.AjaxResult
    */
    
    @Override
    public AjaxResult billingPolicies(ChargingDTO chargingDTO) throws SystemException {
        //获取订单的总距离
        Double orderDistance = chargingDTO.getOrderDistance();
        //获取起步时间
        Double startingKm = chargingDTO.getStartingKm();
        //获取超时的距离
        double outDistance = orderDistance - startingKm;
        //获取超里程每公里的价格
        BigDecimal outOrderDistancePrice = chargingDTO.getOutOrderDistanceUnitPrice();
        //计算超里程的总费用
        chargingDTO.setOutOfDistanceTotalPrice(outOrderDistancePrice
                .multiply(new BigDecimal(outDistance)));
        //计算总费用 订单价格 = 超里程总费用 + 起步价格
        chargingDTO.setOrderPrice(chargingDTO.getOrderPrice()
                .add(chargingDTO.getOutOfDistanceTotalPrice())
                .add(chargingDTO.getStartingPrice()));
        return AjaxResult.success(chargingDTO);
    }
}
